package com.tommy.store.file;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import net.sf.json.JSONArray;

public class SqliteDemo {

    public static DriverManagerDataSource dataSource = null;

    public static void loadDatabase() {
        String localFilePath = System.getProperty("user.home") + "/lowcode_data.db"; // 本地文件路径，存储在用户根目录下

        dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("org.sqlite.JDBC");
        dataSource.setUrl("jdbc:sqlite:" + localFilePath);
        dataSource.setUsername("myusername");
        dataSource.setPassword("mypassword");

    }

    public static void main(String[] args) {

        loadDatabase();
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

        Map<String, String> params = Collections.singletonMap("status", "ACTIVE");
        MapSqlParameterSource source = new MapSqlParameterSource();
        String sql = "select * from comment_info";

        List<Map<String, Object>> aaa = jdbcTemplate.queryForList(sql);

        String result = JSONArray.fromObject(aaa).toString();

        // System.out.println(result);

    }
}
